package com.fzj.charging.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzj.charging.common.pojo.vo.UserInfoVO;
import com.fzj.charging.user.mapper.UserMapper;
import com.fzj.charging.user.mapper.UserVehicleMapper;
import com.fzj.charging.user.pojo.entity.ChargingUserVehicleBind;
import com.fzj.charging.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserVehicleMapper userVehicleMapper;
    @Override
    public UserInfoVO getUserInfo(Integer userId) {
        log.debug("用户服务，查询用户信息业务，参数：{}",userId);
        QueryWrapper<ChargingUserVehicleBind> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("state",1);
        //如果查询结果记录大于1，会抛异常；等于1，正常返回；没查到返回null
        ChargingUserVehicleBind chargingUserVehicleBind = userVehicleMapper.selectOne(queryWrapper);
        log.debug("用户服务，查询用户信息业务，参数：{},查询到的车辆信息：{}",userId,chargingUserVehicleBind);
        UserInfoVO userInfoVO = new UserInfoVO();
        if(chargingUserVehicleBind!=null){
            userInfoVO.setCardId(chargingUserVehicleBind.getVehicleId());
            userInfoVO.setUserId(chargingUserVehicleBind.getUserId());
        }
        return userInfoVO;

    }
}
